package cn.cnhis.online.activity.agreement.view;

import android.content.Context;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.cnhis.online.BuildConfig;
import cn.cnhis.online.R;
import cn.cnhis.online.activity.agreement.contract.IAgreementContract;
import cn.cnhis.online.activity.agreement.presenter.AgreementPresenter;
import cn.cnhis.online.activity.login.view.LoginActivity;
import cn.cnhis.online.activity.main.view.MainActivity;
import cn.cnhis.online.base.ActivityStack;
import cn.cnhis.online.base.BaseMvpActivity;
import cn.cnhis.online.mymodule.Api;
import cn.cnhis.online.mymodule.Utils.PackageUtil;
import cn.cnhis.online.mymodule.Utils.StatusBarUtils;
import cn.cnhis.online.mymodule.sp.MySpUtils;


/**
 * @author 刘祥龙
 * @describe
 * @date 2020/2/29  17:37
 * - generate by MvpAutoCodePlus plugin.
 */

public class AgreementActivity extends BaseMvpActivity<IAgreementContract.View, IAgreementContract.Presenter> implements IAgreementContract.View {

    @BindView(R.id.webview)
    WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityStack.getInstance().pushActivity(this);
        setContentView(R.layout.activity_agreement);
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        setThemeolor();
        initWebview();
    }

    private void initWebview() {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setDatabaseEnabled(true);
//        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setAppCacheEnabled(true);
//        webView.getSettings().setCacheMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.addJavascriptInterface(new JavaScriptinterface(this),
                "Android");
//        webView.loadUrl(URL_web);
        setWebViewMargin(webView);
        webView.loadUrl(Api.EXPLAIN);
    }



    public class JavaScriptinterface {
        Context context;

        public JavaScriptinterface(Context c) {
            context = c;
        }

        @JavascriptInterface
        public void goBack() {
            finish();
        }

    }


    @Override
    public void showErr(String e) {

    }

    @Override
    public IAgreementContract.Presenter createPresenter() {
        return new AgreementPresenter();
    }

    @Override
    public IAgreementContract.View createView() {
        return this;
    }
}

